<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return['post']=array();
if($_RQ['op']=='main'){
	exi($return);
}
set_html('title','我的客户');
if($_RQ['op']=='list'){
	$params=array('worker_id'=>$worker['id'],'uniacid'=>$_SESSION['uniacid']);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$list=pdo_getslice('jy_ailiao_member',$params,array($pindex,$psize),$total,array(),'','createtime desc');
	if($list){
		$current_year=date('Y');
		$zhiweis=$this->model('model')->zhiweis();
		foreach($list as &$member){
			$member['nickname']=$member['nickname']?:$return['item']['nickname'];
			$member['avatar']=$member['avatar']?:$return['item']['avatar'];
			$member['images']=json_decode($member['images'],true);
			$member['birth']=json_decode($member['birth'],true);
			foreach($member['images'] as &$img){
				$img=tomedia($img);
			}
			$member['avatar']=$member['avatar']?:$item['images'][0];
			$member['sextitle']=$this->sex[$member['sex']];
			$member['picsnum']=count($member['images']);
			
			$member['age'] = $member['birth']['year']?$current_year - $member['birth']['year'] - 1:'**';
			$member['height']=$this->heights[$member['height']];
			$member['zhiwei']=$zhiweis[$member['zhiwei']];
		}
	}
	$return['list']=$list;
	$workers=pdo_getall('jy_ailiao_worker',array('uniacid'=>$_SESSION['uniacid']),'','id');
	$workers[0]=array('id'=>0,'title'=>'无红娘');
	$return['isopenvoice']=$this->session('isopenvoice')?1:0;
	$return['workers']=$workers;
	exi($return);
}
//转单
if($_RQ['op']=='change'){
	$post=get_postdata();
	$user_id=intval($post['id']);
	if(!$user_id){
		exi('订单不存在，请重新选择订单','error');
	}
	$member=pdo_get('jy_ailiao_member',array('id'=>$user_id));
	if($post['worker_id']){
		pdo_update('jy_ailiao_member',array('worker_id'=>$post['worker_id']),array('id'=>$user_id));
	}else{
		pdo_update('jy_ailiao_member',array('worker_id'=>0),array('id'=>$user_id));
	}
	exi('转客户成功！');
}